﻿using ProjectFootball.MVC.Foundation.ResourceLibrary;
using ProjectFootball.MVC.Models.EntityFramework.Entities;
using ProjectFootball.MVC.Models.RepositoryProviders;
using System.Security.Principal;
using System.Web.Mvc;


namespace ProjectFootball.MVC.Foundation
{
    public abstract class BaseController : Controller
    {
        public BaseController(IRepositoryProvider provider)
        {
            this.Provider = provider;
        }

        protected IRepositoryProvider Provider;

        protected int UserId
        {
            get { return User.GetUserId(); }
        }

        protected RedirectToRouteResult RedirectHome
        {
            get { return RedirectToAction("Index", "Home", new { area = string.Empty }); }
        }

        protected void SetCreateDbType(IApprovableEntity entity)
        {
            SetDbType(entity.IsPublic ? entity.IsApproved ? DbType.CreatedPublic : DbType.CreatedUnapproved : DbType.CreatedPrivate);
        }

        protected void SetEditDbType(IApprovableEntity entity)
        {
            SetDbType(entity.IsPublic ? entity.IsApproved ? DbType.EditedPublic : DbType.EditedUnapproved : DbType.EditedPrivate);
        }

        protected void SetDbType(DbType dbType)
        {
            TempData["DbType"] = dbType;
        }

    }
}